#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""dummy data format

Copyright (C) 2008-2014 Christian T. Steigies <steigies@physik.uni-kiel.de>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

This module offers functions to read NM data in ASCII format as used in <new station>.
"""

__author__ = "Christian T. Steigies <steigies@physik.uni-kiel.de>"
__license__ = "GPL License"

## --------------------------------------------------------------------------
import sys
from nmdb.tools.configtool import parse_options
from nmdb.tools.datetool import valid_date

dummy_station = ["dumm"]
dummy_long = {"dumm": "Dummy station"}

## --------------------------------------------------------------------------
def read_rt(options, station, data_type, year, month, day):
    """read realtime data

    options     verbose, dryrun, ...
    station     station short name, must be valid station
    data_type   "1m", "1h", "env", "meta"
    year        integer (1950-9999), may not be None
    month       integer (1-12), if None, read month 1-12
    day         integer (1-31), if None, read day 1-31
    
    return list of values in nmdb format
    """

    if station in dummy_station:
        pass
    else:
        raise ValueError  # wrong station

    value = []
    if valid_date(year, month, day):
        value.append(["read_rt for %s (%04i-%02i-%02i)" % (station, year, month, day)])
    
    return value

## --------------------------------------------------------------------------
def read_rev(options, station, data_type, year, month, day):
    """read revised data

    options     verbose, dryrun, ...
    station     station short name, must be valid station
    data_type   "1m", "1h", "env", "meta"
    year        integer (1950-9999), may not be None
    month       integer (1-12), if None, read month 1-12
    day         integer (1-31), if None, read day 1-31
    
    return list of values in nmdb format
    """

    if station in dummy_station:
        pass
    else:
        raise ValueError  # wrong station

    value = []
    if valid_date(year, month, day):
        value.append(["read_rev for %s (%04i-%02i-%02i)" % (station, year, month, day)])
    
    return value

## --------------------------------------------------------------------------
def read_env():
    """read files in the env format
    date_time, temperature_inside, temperature_outside, relative_humidity, wind_speed_m_s
    """

    return None
## --------------------------------------------------------------------------
def read_meta():
    """read files in the meta format
    meta.txt:
    start_date_time, end_date_time, quality, comment

    meta.rev:
    ID, start_date_time, end_date_time, quality, comment
    """

    return None
## --------------------------------------------------------------------------
def main():
    print "This is the dummy station module."

    (options, args) = parse_options("upload")
    if options.verbose > 1:
        print "options:", options
        print "args:", args
    if options.dryrun:
        print "dryrun: not sending any data to NMDB"
    rcfile = options.rcfile

    station = "dumm"
    data_type="1h"
    data_type="1m"
    year = 2014
    month = 10
    day = 12

    data = read_rev(options, station, data_type, year, month, day)
    #data = read_rt(options, station, data_type, year, month, day)
    for line in data:
        print line
    
    return

## --------------------------------------------------------------------------
if __name__ == '__main__':
    main()
    sys.exit(0)
